<%--
  Created by IntelliJ IDEA.
  User: cc又瘦啦
  Date: 2021/12/20
  Time: 11:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>增加</title>
    <script src="${pageContext.request.contextPath}/static/js/jquery-3.4.1.js"></script>
</head>
<body>

<form action="./add" method="post">

    制单人工号:<input type="text" readonly name="user.userId" value="${user.userId}"><br><br>
    制单人:<input type="text" readonly name="user.userName" value="${user.userName}"><br><br>

    商品归属:<input type="text" name="goodsAffiliation"><br><br>
    商品编号:<input type="text" name="goodsId"><br><br>
    商品名称:<input type="text" name="goodsName"><br><br>
    商品类型:
    <select name="type.typeId"></select><br><br>
    品牌:
    <select name="brand.brandId"></select><br><br>

    图片:
    <input type="file" id="file" onchange="upFile()">
    <input type="hidden" name="goodsImg">
    <img src="" id="show" height="50" width="50"><br><br>

    型号:<input type="text" name="goosModel"><br><br>
    规格:<input type="text" name="goodsSpecification"><br><br>
    单价:<input type="text" name="goodsPrice"><br><br>

    <input type="submit"  value="提交"><br><br>

</form>

<script>

    function checkoutMethod() {
        // alert(111)
        // //数值校验
        // var money = $("[name='goodsPrice']").val();
        // var regex="\\d+.\\d{0,2}";
        //onclick="checkoutMethod()"
        // if (money.text(regex)){
        //     alert("123")
        // }

    }

    function upFile(){

        var formData = new FormData();
        formData.append("file",$("#file")[0].files[0]);

        if ($("#file")[0].files[0].size<5*1024*1024){
            $.ajax({
                url:"./upPic",
                contentType:false,
                processData:false,
                data:formData,
                type:"post",
                success:function(fileName){

                    $("#show").prop("src","/pic/"+fileName);
                    $("[name='goodsImg']").val(fileName);
                }
            })
        }else{
            alert("文件图片过大");
        }

    }

    $.post("getBrandList",function (brandList) {

        for (var brand of brandList) {
            $("[name='brand.brandId']").append("<option value='"+brand.brandId+"'>"+brand.brandName+"</option>");
        }

    })

    $.post("getTypeList",function (typeList) {

        for (var type of typeList) {
            $("[name='type.typeId']").append("<option value='"+type.typeId+"'>"+type.typeName+"</option>");
        }

    })


</script>

</body>
</html>
